package com.hd.pzhwlxt.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.hd.pzhwlxt.mapper.OfficeMaterialUsageMapper;
import com.hd.pzhwlxt.pojo.OfficeMaterial;
import com.hd.pzhwlxt.pojo.OfficeMaterialUsage;
import com.hd.pzhwlxt.service.OfficeMaterialService;
import com.hd.pzhwlxt.service.OfficeMaterialUsageService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

/**
@create: 2022-09-23 11:22
@author: 怀念天空
@Description: 
*/

@Service
@Transactional
public class OfficeMaterialUsageServiceImpl extends ServiceImpl<OfficeMaterialUsageMapper, OfficeMaterialUsage> implements OfficeMaterialUsageService{

    @Autowired
    private OfficeMaterialUsageMapper officeMaterialUsageMapper;

    @Autowired
    private OfficeMaterialService officeMaterialService;

    @Override
    public boolean addOfficeMaterialUsage(OfficeMaterialUsage officeMaterialUsage) {
        try {
            OfficeMaterial material = officeMaterialService.getById(officeMaterialUsage.getMaterialId());
            material.setCount(material.getCount() - officeMaterialUsage.getReceiveNum());
            officeMaterialService.updateById(material);
            return officeMaterialUsageMapper.insert(officeMaterialUsage) > 0;
        } catch (Exception e) {
            return false;
        }
    }
}
